package org.example.controller;


import dev.langchain4j.data.message.AiMessage;

import dev.langchain4j.data.message.UserMessage;
import dev.langchain4j.model.chat.ChatLanguageModel;
import dev.langchain4j.model.output.Response;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import org.example.service.ChatAssistant;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;


@RestController
@Slf4j
public class ChatLanguageModelController
{
    @Resource
    private ChatLanguageModel chatLanguageModel;
    @Resource
    private ChatAssistant chatAssistant;

    // http://localhost:9002/chatapi/hello
    //低级
    @GetMapping(value = "/chatapi/hello")
    public String hello(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt)
    {
        String result = chatLanguageModel.generate(prompt);

        System.out.println("通过langchain4j调用qwen-turbo-0624模型返回结果："+result);

        return result;
    }

    //http://localhost:9002/chatapi/lowapi?prompt=%E8%8C%85%E5%8F%B0%E9%85%92%E5%A5%BD%E5%96%9D%E5%90%97
    @GetMapping(value = "/chatapi/lowapi")
    public String lowApi(@RequestParam("prompt") String prompt)
    {

        Response<AiMessage> aiMessageResponse = chatLanguageModel.generate(UserMessage.from(prompt));

        return aiMessageResponse.content().text();
    }

    //高级
    @GetMapping(value = "/chatapi/highapi")
    public String highApi(@RequestParam(value = "prompt", defaultValue = "你是谁") String prompt)
    {
        return chatAssistant.chat(prompt);
    }
}
